var ServerAddress = 'https://www.rj1401.cn/'
angular.module('starter.controllers', [])
	.controller('tabsCtrl', function($scope, $http, $ionicSlideBoxDelegate, $ionicViewSwitcher, $ionicModal) {
		$scope.moredata = false; //没数据不加载

		$scope.me = function() {

			$ionicViewSwitcher.nextDirection('forward');
			if(localStorage.getItem('userphone') != null) {

				location.href = '#/tab/me';
			} else {

				//			localStorage.setItem('longipd',2);
				location.href = '#/login';
			}

		}
		$ionicModal.fromTemplateUrl('templates/fabu.html', {
			scope: $scope
		}).then(function(modal) {
			$scope.modal = modal;
		});
		$scope.fabua = function() {
			console.log(1)
			$scope.modal.hide();

			location.href = "#/publish/自定义主题";

		}
		//获取广告
		$scope.advert = [];
		$http.get(ServerAddress + "api/advert/get").success(function(data) {
			console.log(data);
			for(var i = 0; i < data.length; i++) {
				$scope.advert.push({
					Id: data[i].活动id,
					img: data[i].图片
				});
			}
			$ionicSlideBoxDelegate.loop(true);
			$ionicSlideBoxDelegate.update();
		});

	})

	.controller('SelectedCtrl', function($scope, $http, $ionicSlideBoxDelegate) {

		$scope.zhdizi = function(dizhi, i) {
			var myGeo = new BMap.Geocoder();
			// 将地址解析结果显示在地图上,并调整地图视野
			myGeo.getPoint(dizhi, function(point) {
				if(point) {

					myGeo.getLocation(point, function(rs) {
						var addComp = rs.addressComponents;
						console.log(addComp.district);
						$scope.SActivities[i].dizi = addComp.district;
					});
				} else {

					$scope.SActivities[i].dizi = dizhi;
				}
			}, "北京市");
		}
			$scope.doRefresh = function() {

			//获取广告

			$http.get(ServerAddress + "api/advert/get").success(function(data) {
				$scope.advert = [];
				console.log(data);
				for(var i = 0; i < data.length; i++) {
					$scope.advert.push({
						Id: data[i].活动id,
						img: data[i].图片
					});
				}
				$ionicSlideBoxDelegate.update();

			});
			$http.get(ServerAddress + "api/SActivities/get/"+localStorage.getItem('userphone') )
				.success(function(data) {
					$scope.SActivities = [];
					console.log(data);
					for(var i = 0; i < data.length; i++) {
						
						var kssj = new Date(data[i].开始时间).getTime();
						$scope.SActivities.push({
							tj:data[i].推荐=="True"?1:0,
							sj: data[i].手机号,
							Id: data[i].精选id,
							portrait: data[i].用户头像,
							name: data[i].用户昵称,
							title: data[i].标题,
							ksdate: kssj,
							hdid: data[i].活动id,
							hdfm: data[i].活动封面
						});
						console.log(data[i].精选id);
						$scope.zhdizi(data[i].活动地址, $scope.SActivities.length - 1);
						$scope.jxid = data[data.length - 1].精选id
					}
					$scope.moredata = false
					if(data.length < 10) {
						$scope.moredata = true;
					}
				})
				.finally(function() {
					// Stop the ion-refresher from spinning
					$scope.$broadcast('scroll.refreshComplete');
				});
		};
	
$scope.doRefresh();
		$scope.jxid;
		//上拉加载
		$scope.loadMore = function() {
			$scope.jxid;
			$http.post(ServerAddress + "api/RSActivities/get", {
					Id: $scope.jxid
				},{languageColumn:'name_eu'},{'Content-Type':'application/x-www-form-urlencoded'})
				.success(function(data) {
					//	$scope.SActivities=[];
					//  $scope.zhdizi(data[0].活动地址,11)
					console.log($scope.zhdizi);
					for(var i = 0; i < data.length; i++) {

						var kssj = new Date(data[i].开始时间).getTime();
						$scope.SActivities.push({
							sj: data[i].手机号,
							Id: data[i].精选id,
							portrait: data[i].用户头像,
							name: data[i].用户昵称,
							title: data[i].标题,
							ksdate: kssj,
							hdid: data[i].活动id,
							hdfm: data[i].活动封面,
							dizi: ""
						});
						console.log(data[i].精选id);
						$scope.zhdizi(data[i].活动地址, $scope.SActivities.length - 1)

					}
					if(data.length < 10) {
						$scope.moredata = true;
					}
				})
				.finally(function() {
					// Stop the ion-refresher from spinning
					$scope.$broadcast('scroll.infiniteScrollComplete');
				});
		};
		//下拉刷新
	
	})
	//启动页
	.controller('indexCtrl', function($scope, $interval) {
		$scope.s = 3
		$scope.Selected = function() {
			$interval.cancel(timePromise);
			location.href = '#/tab/Selected';

		}

		timePromise = undefined;
		timePromise = $interval(function() {
			if($scope.s == 0) {
				$interval.cancel(timePromise);
				location.href = '#/tab/Selected';

			} else {
				$scope.s--;
			}
		}, 1000, 100)
	})
	//忘记密码页面控制器
	.controller('forgetCtrl', function($scope, $state, $window, $http, $ionicHistory, $ionicViewSwitcher) {
		wait = 60;
		$scope.phone;
		$scope.pwd;
		$scope.yzm;

		$scope.forget_login = function() {
			$ionicViewSwitcher.nextDirection('back');
			$window.history.back();
		}
		$scope.sjshu = GetRandomNum(10000, 100000);
		$scope.forget_zmy = function() {

			if($scope.phone != null) {
				var strphone = $scope.phone.toString();
				if(strphone.length == 11) {
					$scope.sjshu = GetRandomNum(10000, 100000);
					console.log($scope.sjshu);
					$http.get('http://106.ihuyi.cn/webservice/sms.php?method=Submit&account=cf_ctt&password=123456&mobile=' + zcphone + '&content=您的验证码是：' + '+$scope.sjshu ' + '。请不要把验证码泄露给其他人。').success(function(response) {});
					ftime();
				} else {
					alert('手机号码不准确！');
				}
			} else
				alert('手机不能为空！');

		}
		$scope.forget_pwd = function() {
			console.log($scope.pwd);
			if($scope.pwd == null) {
				console.log($scope.pwd);
				alert('密码不能为空！');
			} else if($scope.yzm == null) {
				alert('验证码不能为空！');
			} else if($scope.phone == null) {
				alert('手机不能为空！');
			} else if($scope.yzm != $scope.sjshu) {

				alert('验证码不正确！');
			} else {
				var json = JSON.stringify({
					手机号: $scope.phone.toString(),
					密码: $scope.pwd
				})
				console.log(json);
				$http.post(ServerAddress + 'api/user/uppwd', json).success(function(data) {
					console.log(data);
					if(data == -1) {
						console.log('帐号不存在');
					} else {
						console.log('修改成功！');
						$ionicViewSwitcher.nextDirection('forward');
						$window.history.back();
					}

				})
			}

		};

	})
	//登录页面控制器
	.controller('LoginCtrl', function($scope, $state, $window, $http, $ionicHistory, $ionicViewSwitcher) {

		$scope.phone ;
		$scope.pwd = "";
		console.log(localStorage.getItem('longipd'));
		$scope.longinpd = function() {
			//			var yb=localStorage.getItem('longipd');
			//			
			//			if(yb==1)
			//			{ 
			$ionicViewSwitcher.nextDirection('back');
			$window.history.back();
			//	location.href='#/tab/publish';
			//	}
			//	else
			//	{
			//		 console.log(yb);
			//		$ionicViewSwitcher.nextDirection('back')
			//		$window.history.back();
			//				$state.go('tab.Selected');
			//location.href='#/tab/Selected';
			//	}
		}
		$scope.login = function() {
			var json = JSON.stringify({
				手机号: $scope.phone.toString(),
				密码: $scope.pwd
			})
			console.log(json);
			$http.post(ServerAddress + 'api/user/login', json).success(function(data) {
				console.log(data['Id']);
				if(data['Id'] > 0) {

					localStorage.setItem('userphone', data['手机号']);
					console.log(localStorage.getItem('userphone'));
					location.href = '#/tab/Selected';
				} else {
					alert('帐号不存在或密码错误！');
				}

			})

		};

	})
	//var zcphone;
	//注册
	.controller('RegisterCtrl', function($scope, $http, $window, $ionicHistory, $ionicViewSwitcher) {

		$scope.phone;
		$scope.gologin = function() {
			$ionicViewSwitcher.nextDirection('back');
			$window.history.back();
		}

		$scope.fsyzm = function() {

			if($scope.phone != null && $scope.phone.toString().length == 11) {
				zcphone = $scope.phone.toString();

				//手机验证码
				//	$http.get('http://106.ihuyi.cn/webservice/sms.php?method=Submit&account=cf_dotnet_yj&password=123456&mobile=' + zcphone + '&content=您的验证码是：' + $scope.sjshu + '。请不要把验证码泄露给其他人。').success(function(response) {});
				//还缺验证手机被注册没
				//	console.log($scope.sjshu);
				$ionicViewSwitcher.nextDirection('forward')
				location.href = '#/register-1';

			} else {
				alert('手机号码错误');
				console.log('手机号码错误');
			}

		}
	})
	//注册-1
	.controller('Register_1Ctrl', function($scope, $ionicViewSwitcher, $window, $http, $state) {
		wait = 60
		time(); //开始运行
		//发送手机验证码
		$scope.sjshu = GetRandomNum(10000, 100000);

		$scope.goreg = function() {
			$ionicViewSwitcher.nextDirection('back');
			$window.history.back();
		}
		console.log($scope.sjshu);
		console.log(zcphone);
		$http.get('http://106.ihuyi.cn/webservice/sms.php?method=Submit&account=cf_ctt&password=123456&mobile=' + zcphone + '&content=您的验证码是：' + $scope.sjshu.toString() + '。请不要把验证码泄露给其他人。').success(function(response) {});

		$scope.reset = function() //重新发送验证码
		{
			time();
			$scope.sjshu = GetRandomNum(10000, 100000);
			//重新验证码
			//	$http.get('http://106.ihuyi.cn/webservice/sms.php?method=Submit&account=cf_ctt&password=123456&mobile=' + zcphone + '&content=您的验证码是：' + '12345' + '。请不要把验证码泄露给其他人。').success(function(response) {});

		};
		$scope.yzm;
		$scope.mima;
		$scope.yinzhen = function() {
			if($scope.yzm == $scope.sjshu) {
				if($scope.mima != null) {
					zcmima = $scope.mima;
					location.href = '#/register-2';
				} else {
					alert('密码不能为空！');
				}
			} else {
				alert('验证码错误！');
			}
			//#/tab/register-2
		}
	})
	//注册-2提交
	.controller('Register_2Ctrl', function($ionicLoading, $scope, $http, $ionicViewSwitcher, $window, $state, $timeout) {

		$("#riao1").click(function() {

			$(this).find(".iconfont").css("color", '#3b9ce9');
			$(this).find("span").css("color", '#000');

			$('#riao2').find(".iconfont").css("color", '#ccc');
			$('#riao2').find("span").css("color", '#ccc');

		});
		$("#riao2").click(function() {

			$(this).find(".iconfont").css("color", 'rgb(198,0,0)');
			$(this).find("span").css("color", '#000');
			$('#riao1').find(".iconfont").css("color", '#ccc');
			$('#riao1').find("span").css("color", '#ccc');

		});

		$scope.FormData = null;
		var hdfm = document.getElementById('hdfm');
		hdfm.addEventListener('change', readFile, false);

		function readFile() {
			var file = this.files[0];
			var value = $("#hdfm").val();
			//	$ionicLoading.show();
			if(value == null || value == "") {

			} else {

				//这里我们判断下类型如果不是图片就返回 去掉就可以上传任意文件 
				if(!/image\/\w+/.test(file.type)) {
					alert("请确保文件为图像类型");
					return false;
				}
				var reader = new FileReader();
				reader.readAsDataURL(file);
				//console.log(this.result); 

				reader.onload = function(e) {
					//console.log(this.result);

					$scope.FormData = this.result;
					//	$ionicLoading.hide();

				}
			}
		}
		$scope.change = function() {

			var formData = new FormData($("#uploadForm")[0]);
			var hdfm = document.getElementById('hdfm');
			$.ajax({
				url: ServerAddress + 'api/' + zcphone + '/image/upload',
				type: 'POST',
				data: formData,
				cache: false,
				contentType: false,
				processData: false,
				success: function(data) {
					console.log(data);
					$timeout(function() {
						//		$ionicLoading.hide();

						$scope.FormData = data;

					}, 3000);
				},
				error: function(returndata) {
					console.log(returndata);
				}
			})

			// $ionicLoading.show();

		}
		$scope.csfm = function() {
			var hdfm = document.getElementById('hdfm');
			hdfm.click();
		}
		$scope.FormData = 'http://ogzbtvflm.bkt.clouddn.com/18058300201-sj-2017-3-17-22-40-34-sjs-582.jpg';
		$scope.zcname;
		$scope.xb = '男';
		$scope.sr;
		$scope.goregyzm = function() {
			$ionicViewSwitcher.nextDirection('back');
			$window.history.back();
		}
		$scope.tishi = function(str) //提示
		{
			$ionicLoading.show({
				template: str,
				noBackdrop: true,
				duration: 1000
			});
		}

		$scope.zcwc = function() {
			console.log(zcphone);
			console.log(zcmima);
			console.log($scope.src);
			console.log($scope.zcname);
			console.log($scope.xb);
			console.log($scope.sr);
			var json = JSON.stringify({
				手机号: zcphone,
				昵称: $scope.zcname,
				头像: $scope.FormData,
				生日: $scope.sr,
				性别: $scope.xb,
				密码: zcmima
			});
			$http.post(ServerAddress + "api/user/add", json).success(function(response) {
				console.log(response);
				if(response == 1) {
					$scope.tishi('注册成功！');
					console.log(localStorage.setItem('userphone', zcphone));
					location.href = '#/tab/Selected';
				} else {
					$scope.tishi('注册失败！');
				}
			});
		}
		//#/tab/login
	})

	//动态
	.controller('dongtai1', function($scope, $ionicModal, $ionicLoading, $http, $ionicViewSwitcher, $window, $state, $timeout) {

		$scope.tishi = function(str) //提示
		{
			$ionicLoading.show({
				template: str,
				noBackdrop: true,
				duration: 1000
			});
		}
		$scope.remove = function(index, id) {
			$http.get(ServerAddress + "api/move/" + id + "/del").success(function(data) {
				if(data == 1) {
					$scope.tishi('删除成功!');
					$scope.doRefresh();
				} else {
					$scope.tishi('删除失败!');
				}
				console.log($scope.move);
			})

		}
		$scope.doRefresh = function() {
			$scope.move = [];
			$http.get(ServerAddress + "api/move/" + localStorage.getItem('userphone') + "/get").success(function(data) {
					console.log(data);
					data = JSON.parse(data);
					console.log(data);
					for(var i = 0; i < data.length; i++) {
						var aa;
						if(data[i].图片[0] == undefined) {
							aa = null;
						} else {
							aa = data[i].图片[0].图片地址;
						}
						$scope.move.push({
							Id: data[i].id,
							img: aa,
							name: data[i].用户名,
							tx: data[i].用户头像,
							cont: data[i].内容,
							fbdate: data[i].评论时间,
							sj: data[i].手机号,
							z: data[i].点赞
						});

						console.log($scope.move);
					}
				})
				.finally(function() {
					// Stop the ion-refresher from spinning
					$scope.$broadcast('scroll.refreshComplete');
				})
		}

		$scope.doRefresh();
	})
	//动动
	.controller('MoveCtrl', function($ionicPopup, $scope, $ionicModal, $ionicLoading, $http, $ionicViewSwitcher, $window, $state, $timeout) {
		//登录框
		$scope.showConfirm = function() {
			var confirmPopup = $ionicPopup.confirm({
				title: '提示框',
				template: '请先登入!',
				okText: '是',
				cancelText: '否'
			});
			confirmPopup.then(function(res) {
				if(res) {
					localStorage.setItem('longipd', 1);
					console.log(localStorage.getItem('userphone'));
					console.log(localStorage.getItem('longipd'));
					$ionicViewSwitcher.nextDirection('forward')
					//			//	$state.go('tab.login');
					location.href = '#/login';
				} else {
					console.log('You are not sure');
				}
			});
		};
		$scope.tishi = function(str) //提示
		{
			$ionicLoading.show({
				template: str,
				noBackdrop: true,
				duration: 1000
			});
		}
		$ionicModal.fromTemplateUrl('templates/dd_fabu.html', {
			scope: $scope
		}).then(function(modal) {
			console.log(1);
			$scope.modala = modal;
		});
		$scope.modalashow = function() {
			if(localStorage.getItem('userphone') != null) {
				$scope.modala.show();
				var text = document.getElementById('fa_text').innerText;
				document.getElementById('fa_text').innerText = "";
				$scope.FormData = null;
				text = "";

			} else {
				$scope.showConfirm();
			}
		}
		$scope.FormData = null;

		$scope.goreg = function() {
			var text = document.getElementById('fa_text').innerText;
			console.log(text.replace(/\s+/g, "").length)
			if(text.replace(/\s+/g, "").length != 0) {
				var json = JSON.stringify({
					内容: text
				});
				$http.post(ServerAddress + 'api/move/' + localStorage.getItem('userphone') + '/add', json).success(function(data) {
					console.log(data);
					if(data != 0) {
						if($scope.FormData != null) {
							var jon = JSON.stringify({
								动态Id: data,
								图片地址: $scope.FormData
							});
							$http.post(ServerAddress + 'api/movefj/' + localStorage.getItem('userphone') + '/add', jon).success(function(data) {

								console.log(data);

							})

						}

						$scope.doRefresh();
						document.getElementById('fa_text').innerText = "";
						$scope.modala.hide();
						console.log($scope.FormData);
						$scope.tishi('发布成功！');
					}

				})
			} else {
				$scope.tishi("内容为空!");
			}
		}
		$scope.move = [];
		$scope.change = function() {

			var formData = new FormData($("#uploadForm")[0]);
			var hdfm = document.getElementById('hdfm');
			$.ajax({
				url: ServerAddress + 'api/' + localStorage.getItem('userphone') + '/image/upload',
				type: 'POST',
				data: formData,
				cache: false,
				contentType: false,
				processData: false,
				success: function(data) {
					console.log(data);
					$timeout(function() {
						//		$ionicLoading.hide();

						$scope.FormData = data;

					}, 3000);
				},
				error: function(returndata) {
					console.log(returndata);
				}
			})

			// $ionicLoading.show();

		}
		$scope.csfm = function() {
			var hdfm = document.getElementById('hdfm');
			hdfm.click();
		}
		$scope.doRefresh = function() {
			$scope.move = [];
			$http.get(ServerAddress + "api/move/get").success(function(data) {
					console.log(data);
					data = JSON.parse(data);
					console.log(data);
					for(var i = 0; i < data.length; i++) {
						var aa;
						if(data[i].图片[0] == undefined) {
							aa = null;
						} else {
							aa = data[i].图片[0].图片地址;
						}
						$scope.move.push({
							Id: data[i].id,
							img: aa,
							name: data[i].用户名,
							tx: data[i].用户头像,
							cont: data[i].内容,
							fbdate: data[i].评论时间,
							sj: data[i].手机号,
							z: data[i].点赞
						});

						console.log($scope.move);
					}
				})
				.finally(function() {
					// Stop the ion-refresher from spinning
					$scope.$broadcast('scroll.refreshComplete');
				});
		}
		$scope.doRefresh();
		$scope.nerpd = 1;
		$scope.qweq = '';
		$scope.show1 = function(id) {
			//console.log(id);		
			var box1 = document.getElementById(id);
			var box2 = document.getElementById(id + '-1');
			$scope.qweq = box2.innerHTML;

			box1.innerHTML = $scope.qweq.substring(0, 130);
			var f = 0
			var text = $scope.qweq.length > 130 ? f = 1 : f = 0;
			box1.innerHTML = $scope.qweq.substring(0, 130) + (f == 1 ? '...' : '');
			return f;
			//	console.log(box.innerHTML.length);

		}
		$scope.show2 = function(id) {
			$("#" + id + '-2').css("background-color", "#aaa");
			setTimeout(function() { //定时器
					$("#" + id + '-2').css("background-color", "#fff");
				},
				10);

			var box1 = document.getElementById(id);
			var box2 = document.getElementById(id + '-1');
			var box3 = document.getElementById(id + '-2');
			if(box1.style.display != 'none') {
				box1.style.display = 'none';
				box2.style.display = 'block';
				box3.innerHTML = '收起全文';
			} else {
				box1.style.display = 'block';
				box2.style.display = 'none';
				box3.innerHTML = '查看全文';
			}

		}
	})
	//意见反馈
	.controller('set_feedbackCtrl', function($window, $ionicLoading, $scope, $http, $state, $ionicViewSwitcher) {

		$scope.tishi = function(str) //提示
		{
			$ionicLoading.show({
				template: str,
				noBackdrop: true,
				duration: 1000
			});
		}

		$scope.$on('$ionicView.beforeEnter', function() {
			if(localStorage.getItem('userphone') != null) {
				$scope.feedback = function() {
					var json1 = JSON.stringify({
						内容: document.getElementById('cont').value,
						联系方式: document.getElementById('txt').value,

					});
					console.log(json1);
					$http.post(ServerAddress + 'api/Opinion/' + localStorage.getItem('userphone') + '/add', json1).success(function(data) {

						if(data == 1) {
							$scope.tishi("反馈成功");
							$ionicViewSwitcher.nextDirection('back');
							$window.history.back();
						}

					})

				}
			} else {
				console.log(localStorage.getItem('userphone'));
				localStorage.setItem('longipd', 2);
				$ionicViewSwitcher.nextDirection('forward')
				console.log(localStorage.getItem('longipd'));
				location.href = '#/login'
				//				$state.go('tab.login');
			}
		})

	})

	//修改个人资料set_dataCtrl
	.controller('set_dataCtrl', function($timeout, $window, $ionicLoading, $scope, $http, $state, $ionicViewSwitcher) {

		//	$scope.FormData = null;;
		$scope.tishi = function(str) //提示
		{
			$ionicLoading.show({
				template: str,
				noBackdrop: true,
				duration: 1000
			});
		}
		$scope.$on('$ionicView.beforeEnter', function() {
			if(localStorage.getItem('userphone') != null) {
				var json = JSON.stringify({
					手机号: localStorage.getItem('userphone')
				});
				$http.post(ServerAddress + 'api/user/me', json).success(function(data) {

					data = JSON.parse(data);
					$scope.FormData = data[0].头像;
					$scope.name = data[0].昵称;
					$scope.sr = new Date(data[0].生日);

					$scope.xb = data[0].性别;
					if($scope.xb == '男') {
						$("#riao1").click();
					} else {
						$("#riao2").click();
					}

				})

				$scope.updata = function() {
					var json1 = JSON.stringify({
						手机号: localStorage.getItem('userphone'),
						性别: $scope.xb,
						昵称: $scope.name,
						生日: $scope.sr,
						头像: $scope.FormData
					});

					$http.post(ServerAddress + 'api/user/upzl', json1).success(function(data) {

						if(data == 1) {
							$scope.tishi("修改成功");
							$ionicViewSwitcher.nextDirection('back');
							$window.history.back();
						}

					})

				}

				var hdfm = document.getElementById('hdfm');
				hdfm.addEventListener('change', readFile, false);

				function readFile() {
					var file = this.files[0];
					var value = $("#hdfm").val();
					//	$ionicLoading.show();
					if(value == null || value == "") {

					} else {

						//这里我们判断下类型如果不是图片就返回 去掉就可以上传任意文件 
						if(!/image\/\w+/.test(file.type)) {
							alert("请确保文件为图像类型");
							return false;
						}
						var reader = new FileReader();
						reader.readAsDataURL(file);
						//console.log(this.result); 

						reader.onload = function(e) {
							//console.log(this.result);

							$scope.FormData = this.result;
							//	$ionicLoading.hide();

						}
					}
				}
				$scope.change = function() {

					var formData = new FormData($("#uploadForm")[0]);
					var hdfm = document.getElementById('hdfm');
					$.ajax({
						url: ServerAddress + 'api/' + localStorage.getItem('userphone') + '/image/upload',
						type: 'POST',
						data: formData,
						cache: false,
						contentType: false,
						processData: false,
						success: function(data) {
							console.log(data);
							$timeout(function() {
								//		$ionicLoading.hide();

								$scope.FormData = data;

							}, 3000);
						},
						error: function(returndata) {
							console.log(returndata);
						}
					})

					// $ionicLoading.show();

				}
				$scope.csfm = function() {
					var hdfm = document.getElementById('hdfm');
					hdfm.click();
				}
			} else {
				console.log(localStorage.getItem('userphone'));
				localStorage.setItem('longipd', 2);
				$ionicViewSwitcher.nextDirection('forward')
				console.log(localStorage.getItem('longipd'));
				location.href = '#/login'
			}
		})

	})

	//我
	.controller('MeCtrl', function($scope, $http, $state, $ionicViewSwitcher) {
		$scope.tx;
		$scope.$on('$ionicView.beforeEnter', function() {
			if(localStorage.getItem('userphone') != null) {
				//	localStorage.removeItem('userphone');
				console.log(localStorage.getItem('userphone'));
				var json = JSON.stringify({
					手机号: localStorage.getItem('userphone')
				});
				$http.post(ServerAddress + 'api/user/me', json).success(function(data) {

					data = JSON.parse(data);
					console.log(data);
					$scope.tx = data[0].头像;
					$scope.txObj = {
						"background-image": "url('" + $scope.tx + "')",
						"background-size": "100% 100%"
					}
					$scope.name = data[0].昵称;
					$scope.sc = data[0].收藏;
					$scope.gz = data[0].好友;
					$scope.hd = data[0].活动;
					$scope.sr = new Date().getFullYear() - new Date(data[0].生日).getFullYear();
					console.log($scope.sr);
					$scope.xb = data[0].性别;
					if($scope.xb == '男') {
						$scope.xbObj = {
							"background-color": "#60cffc"
						}
						//男
						$scope.xbcss = 'iconfont icon-icon ';
					} else {
						$scope.xbObj = {
							"background-color": "#fd7b93"
						}
						$scope.xbcss = 'iconfont icon-icon-copy '; //女

					}
					//	localStorage.setItem('userphone',data['手机号']);
					//	console.log(localStorage.getItem('userphone'));
					//		location.href = '#/tab/Selected';
				})
			} else {
				console.log(localStorage.getItem('userphone'));
				localStorage.setItem('longipd', 2);
				$ionicViewSwitcher.nextDirection('forward')
				console.log(localStorage.getItem('longipd'));
				location.href = '#/login'
				//				$state.go('tab.login');
			}
		})

	})

	//用户资料userCtrl
	.controller('userCtrl', function($window, $ionicLoading, $timeout, $scope, $http, $ionicPopup, $stateParams, $ionicViewSwitcher) {

		$scope.back = function() {
			$ionicViewSwitcher.nextDirection('back');
			$window.history.back();

		}
		$scope.$on('$ionicView.beforeEnter', function() {
			var json = JSON.stringify({
				手机号: $stateParams.userId
			});

			$http.post(ServerAddress + 'api/user/me', json,{languageColumn:'name_eu'},{'Content-Type':'application/x-www-form-urlencoded'}).success(function(data) {

				data = JSON.parse(data);
				console.log(data);
				$scope.tx = data[0].头像;

				$scope.name = data[0].昵称;

				$scope.sr = new Date().getFullYear() - new Date(data[0].生日).getFullYear();

				$scope.xb = data[0].性别;
				if($scope.xb == '男') {
					$scope.xbObj = {
						"background-color": "#60cffc"
					}
					//男
					$scope.xbcss = 'iconfont icon-icon ';
				} else {
					$scope.xbObj = {
						"background-color": "#fd7b93"
					}
					$scope.xbcss = 'iconfont icon-icon-copy '; //女

				}
				//	localStorage.setItem('userphone',data['手机号']);
				//	console.log(localStorage.getItem('userphone'));
				//		location.href = '#/tab/Selected';
			})

		})

	})
	//活动
	.controller('huodong-conCtrl', function($window, $ionicLoading, $timeout, $scope, $http, $ionicPopup, $stateParams, $ionicViewSwitcher) {
		//	console.log($stateParams.huodongId);

		var user; //用户手机号
		$scope.sfgz = false; //是否关注
		$scope.$on('$ionicView.beforeEnter', function() {
			$scope.hd_hdid = $stateParams.huodongId;
			user = localStorage.getItem('userphone');
			$scope.sfliek = false; //是不是已经收藏
			$scope.hd_GetActivities = []; //活动内容
			$scope.hd_Getsignup = []; //报名
			$scope.hd_Getdiscuss = []; //评论
			$scope.discussid = 0; //记录评论id
			$scope.gdpl = true; //用来显示更多评论
			$scope.back = function() {
				$ionicViewSwitcher.nextDirection('back');
				$window.history.back();

			}
			//登录框
			$scope.showConfirm = function() {
				var confirmPopup = $ionicPopup.confirm({
					title: '提示框',
					template: '请先登入!',
					okText: '是',
					cancelText: '否'
				});
				confirmPopup.then(function(res) {
					if(res) {
						localStorage.setItem('longipd', 1);
						console.log(localStorage.getItem('userphone'));
						console.log(localStorage.getItem('longipd'));
						$ionicViewSwitcher.nextDirection('forward')
						//			//	$state.go('tab.login');
						location.href = '#/login';
					} else {
						console.log('You are not sure');
					}
				});
			};
			$scope.tishi = function(str) //提示
			{
				$ionicLoading.show({
					template: str,
					noBackdrop: true,
					duration: 1000
				});
			}
			var json = JSON.stringify({
				Id: $scope.hd_hdid
			})
			//获得活动内容
			$http.post(ServerAddress + "api/hd_GetActivities/get", json).success(function(data) {
				for(var i = 0; i < data.length; i++) {

					var kssj = new Date(data[i].开始时间).getTime();
					var jssj = new Date(data[i].结束时间).getTime();
					var bmjzsj = new Date(data[i].报名截止时间).getTime();
					var fbsj = new Date(data[i].发布时间).getTime();

					$scope.hd_GetActivities.push({
						Id: data[i].用户id,
						portrait: data[i].头像,
						name: data[i].昵称,
						title: data[i].标题,
						bmjzdate: bmjzsj,
						ksdate: kssj,
						jsdate: jssj,
						content: data[i].内容,
						hdfm: data[i].主题图片,
						dizi: data[i].活动地址,
						Likecount: data[i].喜欢人数,
						Readcount: data[i].阅读人数,
						fbdate: fbsj,
						phone: data[i].手机号
					});

				}
				$scope.$broadcast('scroll.infiniteScrollComplete');
				console.log(data);
				var json1 = JSON.stringify({
					用户Id: $scope.hd_GetActivities[0].Id
				})
				if(user != null) {
					$http.post(ServerAddress + "api/pdfollow/" + user + "/get", json1).success(function(data) {
						if(data == 1)
							$scope.sfgz = true;

					});
				} else {
					$scope.sfgz = false;
				}

			});

			var like = JSON.stringify({
				活动Id: $scope.hd_hdid
			})
			//获取收藏状态
			if(user != null) {
				$http.post(ServerAddress + "api/like/" + user + "/get", like).success(function(data) {
					if(data == 1) {
						$scope.sfliek = true;

					}
				});
			}
			var getdiscuss = JSON.stringify({
				活动Id: $scope.hd_hdid
			})

			//获取评论
			$http.post(ServerAddress + "api/discuss/get", getdiscuss).success(function(data) {
				data = JSON.parse(data);
				console.log(data);
				for(var i = 0; i < data.length; i++) {
					$scope.discussid = data[i].id;
					var plsj1 = new Date(data[i].评论时间).getTime() - (60000 * 60 * 8);

					$scope.hd_Getdiscuss.push({
						name: data[i].用户名,
						tx: data[i].用户头像,
						id: data[i].用户id,
						plsj: plsj1,
						con: data[i].内容,
						phone: data[i].手机号
					});

				}
				if(data.length < 4) {
					$scope.gdpl = false;
				}

			});

			//获取报名信息
			$http.post(ServerAddress + "api/signup/get", json).success(function(data) {
				data = JSON.parse(data);
				for(var i = 0; i < data.length; i++) {
					$scope.hd_Getsignup.push({
						name: data[i].姓名,
						tx: data[i].头像
					});

				}

			})

		});

		//报名
		$scope.signup_add = function() {
			console.log(user)
			if(user != null) {
				var json = JSON.stringify({
					用户Id: $scope.hd_GetActivities[0].Id
				})

				$scope.showPopup = function() {
					$scope.data = {}
					// 自定义弹窗
					var myPopup = $ionicPopup.show({
						template: '<input placeholder="姓名"  type="text" ng-model="data.name"><br><input placeholder="手机号" type="number" ng-model="data.phone">',
						title: '请填写报名信息',
						scope: $scope,
						buttons: [{
								text: '取消'
							},
							{
								text: '<b>报名</b>',
								type: 'button-positive',
								onTap: function(e) {
									if($scope.data.name != null && $scope.data.phone != null && $scope.data.phone > 12345678901) {

										var json = JSON.stringify({
											活动Id: $scope.hd_hdid,
											姓名: $scope.data.name,
											联系方式: $scope.data.phone
										})
										$http.post(ServerAddress + "api/signup/" + user + "/add", json).success(function(data) {
											console.log(data, json)
											if(data == 0)
												$scope.tishi('不能重复报名');
											else if(data == -1)
												$scope.tishi('不能报名自己的活动')
											else if(data == 1) {
												$scope.tishi('报名成功');
												$scope.hd_Getsignup = [];

												var json = JSON.stringify({
													Id: $scope.hd_hdid
												})
												//获取报名信息
												$http.post(ServerAddress + "api/signup/get", json).success(function(data) {
													data = JSON.parse(data);
													for(var i = 0; i < data.length; i++) {
														$scope.hd_Getsignup.push({
															name: data[i].姓名,
															tx: data[i].头像
														});

													}

												});
											}

										});

										//必须输入Wifi密码
										//   e.preventDefault();
									} else {
										if($scope.data.name == null)
											$scope.tishi('请填写：姓名');
										else if($scope.data.phone == null)
											$scope.tishi('请填写：手机');
										else
											$scope.tishi('确保手机号码正确');

										e.preventDefault();

									}
								}
							}
						]
					});
					myPopup.then(function(res) {
						console.log('Tapped!', res);
					});
				};
				$scope.showPopup();
			} else
				$scope.showConfirm();
		}
		//讨论
		$scope.hddiscuss_add = function() {
			console.log(user)
			if(user != null) {

				$scope.showPopup = function() {
					$scope.data = {}
					// 自定义弹窗
					var myPopup = $ionicPopup.show({
						template: '<input placeholder="内容"  type="text" ng-model="data.con">',
						title: '我要讨论',
						scope: $scope,
						buttons: [{
								text: '取消'
							},
							{
								text: '<b>发送</b>',
								type: 'button-positive',
								onTap: function(e) {
									if($scope.data.con != null) {

										var json = JSON.stringify({
											活动Id: $scope.hd_hdid,
											内容: $scope.data.con
										})
										$http.post(ServerAddress + "api/discuss/" + user + "/add", json).success(function(data) {
											if(data == "0")
												$scope.tishi('用户不存在')
											else {
												$scope.tishi('发送成功');
												data = JSON.parse(data);
												for(var i = 0; i < data.length; i++) {
													var plsj1 = new Date(data[i].评论时间).getTime()
													$scope.hd_Getdiscuss.push({
														name: data[i].用户名,
														tx: data[i].用户头像,
														id: data[i].用户id,
														plsj: plsj1,
														con: data[i].内容,
														phone: data[i].手机号
													});

												}
											}
										});

									} else {
										if($scope.data.con == null)
											$scope.tishi('请填写：内容');
										e.preventDefault();

									}
								}
							}
						]
					});
					myPopup.then(function(res) {
						console.log('Tapped!', res);
					});
				};
				$scope.showPopup();
			} else
				$scope.showConfirm();
		}

		//讨论回复
		$scope.hddiscuss_add2 = function(str) {
			console.log(user)
			if(user != null) {

				$scope.showPopup = function() {
					$scope.data = {}
					// 自定义弹窗
					var myPopup = $ionicPopup.show({
						template: '<input placeholder="回复' + str + ':"  type="text" ng-model="data.con">',
						title: '我要讨论',
						scope: $scope,
						buttons: [{
								text: '取消'
							},
							{
								text: '<b>发送</b>',
								type: 'button-positive',
								onTap: function(e) {
									if($scope.data.con != null) {
										$scope.data.con = "回复" + str + "：" + $scope.data.con;
										var json = JSON.stringify({
											活动Id: $scope.hd_hdid,
											内容: $scope.data.con
										})
										$http.post(ServerAddress + "api/discuss/" + user + "/add", json).success(function(data) {
											console.log(data, json)

											if(data == "0")
												$scope.tishi('用户不存在')
											else {
												$scope.tishi('发送成功');
												data = JSON.parse(data);
												console.log(data);
												for(var i = 0; i < data.length; i++) {
													var plsj1 = new Date(data[i].评论时间).getTime()
													$scope.hd_Getdiscuss.push({
														name: data[i].用户名,
														tx: data[i].用户头像,
														id: data[i].用户id,
														plsj: plsj1,
														con: data[i].内容,
														phone: data[i].手机号
													});

												}
											}
										});

									} else {
										if($scope.data.con == null)
											$scope.tishi('请填写：回复内容');
										e.preventDefault();

									}
								}
							}
						]
					});
					myPopup.then(function(res) {
						console.log('Tapped!', res);
					});
				};
				$scope.showPopup();
			} else
				$scope.showConfirm();
		}

		//加载更多讨论
		//$scope.discussid
		$scope.hddiscuss_get = function() {
			var getdiscuss2 = JSON.stringify({
				活动Id: $scope.hd_hdid,
				Id: $scope.discussid
			})

			//获取更多评论
			$http.post(ServerAddress + "api/discuss/get2", getdiscuss2).success(function(data) {
				data = JSON.parse(data);
				for(var i = 0; i < data.length; i++) {
					$scope.discussid = data[i].id;
					console.log(new Date(data[i].评论时间).getTime())
					var plsj1 = new Date(data[i].评论时间).getTime() - (60000 * 60 * 8);
					console.log(plsj1)
					$scope.hd_Getdiscuss.push({
						name: data[i].用户名,
						tx: data[i].用户头像,
						id: data[i].用户id,
						plsj: plsj1,
						con: data[i].内容,
						phone: data[i].手机号
					});

				}
				if(data.length < 4) {
					$scope.gdpl = false;
				}

			});
		}
		//收藏
		$scope.liekadd = function() {
			if(user != null) {

				var json = JSON.stringify({
					活动Id: $scope.hd_hdid
				})
				if($scope.sfliek == false) {
					$http.post(ServerAddress + "api/like/" + user + "/add", json).success(function(data) {
						if(data == 0)
							$scope.tishi('已经收藏');
						else if(data == -1)
							$scope.tishi('不能收藏自己的活动')
						else if(data == 1) {
							$scope.tishi('已收藏');
							$scope.hd_GetActivities[0].Likecount = parseInt($scope.hd_GetActivities[0].Likecount) + 1;
							$scope.sfliek = true;
						}
					});

				} else {
					$http.post(ServerAddress + "api/like/" + user + "/del", json).success(function(data) {
						if(data == 1) {
							$scope.tishi('取消收藏');
							$scope.hd_GetActivities[0].Likecount = parseInt($scope.hd_GetActivities[0].Likecount) - 1;
							$scope.sfliek = false;
						}
					});
				}
			} else
				$scope.showConfirm();
		}
		//关注
		$scope.follow_add = function() {

			if(user != null) {
				var json = JSON.stringify({
					用户Id: $scope.hd_GetActivities[0].Id
				})

				$http.post(ServerAddress + "api/follow/" + user + "/get", json).success(function(data) {
					if(data == 1) {
						$scope.tishi('已关注');
						$scope.sfgz = true;
					} else
						$scope.tishi('不能关注自己');
				});
			} else
				$scope.showConfirm();

		}
		//取消关注
		$scope.follow_del = function() {

			var json = JSON.stringify({
				用户Id: $scope.hd_GetActivities[0].Id
			})

			$http.post(ServerAddress + "api/qxfollow/" + user + "/get", json).success(function(data) {
				if(data == 1) {
					$scope.tishi('取消关注');
					$scope.sfgz = false;
				}
			});

		}

	})

	//查看报名
	.controller('bmCtrl', function($window, $ionicLoading, $timeout, $scope, $http, $ionicPopup, $stateParams, $ionicViewSwitcher) {
		$scope.back = function() {
			$ionicViewSwitcher.nextDirection('back');
			$window.history.back();

		}
		$scope.bm_hd = function() {

			$scope.hd_hdid = $stateParams.huodongId;
			var json = JSON.stringify({
				Id: $scope.hd_hdid
			})
			$http.post(ServerAddress + "api/signup/get", json).success(function(data) {
				$scope.hd_Getsignup = [];
				data = JSON.parse(data);
				for(var i = 0; i < data.length; i++) {
					$scope.hd_Getsignup.push({
						name: data[i].姓名,
						tx: data[i].头像,
						phone: data[i].联系
					});

				}

			}).finally(function() {
				// Stop the ion-refresher from spinning
				$scope.$broadcast('scroll.refreshComplete');
			});
		}
		$scope.bm_hd();
		$scope.doRefresh = function() {

			$scope.bm_hd();

		}

	})
	//活动地图
	.controller('huodong_mapCtrl', function($scope, $stateParams, $ionicViewSwitcher, $window) {
		//	console.log($stateParams.huodongId);
		$scope.back = function() {
			console.log(10);
			$ionicViewSwitcher.nextDirection('back');
			$window.history.back();

		}
		console.log($stateParams.map);
		var map = new BMap.Map("allmap");
		var point = new BMap.Point(116.331398, 39.897445);
		map.centerAndZoom(point, 15);
		map.addControl(new BMap.NavigationControl());
		map.enableScrollWheelZoom(true);
		var x, y;

		var geolocation = new BMap.Geolocation();
		geolocation.getCurrentPosition(function(r) {
			if(this.getStatus() == BMAP_STATUS_SUCCESS) {
				//var mk = new BMap.Marker(r.point);
				//	map.addOverlay(mk);
				//	map.panTo(r.point);
				//map.removeOverlay(mk);
				//	alert('您的位置：'+r.point.lng+','+r.point.lat);
				point = new BMap.Point(r.point.lng, r.point.lat);

				var pt = point;
				var output = "";
				//map.enableScrollWheelZoom(true);
				var searchComplete = function(results) {
					if(transit.getStatus() != BMAP_STATUS_SUCCESS) {
						return;
					}
					var plan = results.getPlan(0);
					output += plan.getDistance(true); //获取距离
				}
				var transit = new BMap.DrivingRoute(map, {
					renderOptions: {
						map: map
					},
					onSearchComplete: searchComplete,
					autoViewport: true,
					onPolylinesSet: function() {
						setTimeout(function() {
							console.log(output)
						}, "1000");

					}
				});

				transit.search(pt, $stateParams.map);

			} else {
				alert('failed' + this.getStatus());
			}
		}, {
			enableHighAccuracy: true
		})

	})
	//发现界面-活动
	.controller('faxian-activityCtrl', function($ionicLoading, $timeout, $scope, $http, $ionicPopup, $stateParams, $ionicViewSwitcher) {
		console.log($stateParams.activityId);
		$scope.aaa = $stateParams.activityId;
		$scope.moredata = false;
		
		$scope.zhdizi = function(dizhi, i) {
			var myGeo = new BMap.Geocoder();
			// 将地址解析结果显示在地图上,并调整地图视野
			myGeo.getPoint(dizhi, function(point) {
				if(point) {

					myGeo.getLocation(point, function(rs) {
						var addComp = rs.addressComponents;
						console.log(addComp.district);
						$scope.hd_list[i].dizi = addComp.district;
					});
				} else {

					$scope.hd_list[i].dizi = dizhi;
				}
			}, "北京市");
		}

		$scope.title = $stateParams.activityId;
		$scope.hd_list = []; //活动列表
		$scope.sf_new = true; //判断是否最新
		$scope.count = 0;
		$scope.cx = false;
		$scope.moredata = false;

		console.log($scope.moredata);

		//距离
		$scope.juli = function(str, i) {

			var id = i;

			var map = new BMap.Map("allmap");
			var point = new BMap.Point(116.331398, 39.897445);
			map.centerAndZoom(point, 15);
			map.addControl(new BMap.NavigationControl());
			map.enableScrollWheelZoom(true);
			var geolocation = new BMap.Geolocation();
			geolocation.getCurrentPosition(function(r, i) {
				if(this.getStatus() == BMAP_STATUS_SUCCESS) {

					point = new BMap.Point(r.point.lng, r.point.lat);

					var pt = point;
					var output = "";
					var searchComplete = function(results) {
						if(transit.getStatus() != BMAP_STATUS_SUCCESS) {
							return;
						}
						var plan = results.getPlan(0);
						output += plan.getDistance(true); //获取距离

					}
					var transit = new BMap.DrivingRoute(map, {
						renderOptions: {
							map: map
						},
						onSearchComplete: searchComplete,
						autoViewport: true,
						onPolylinesSet: function() {
							//$scope.hd_list[i].juli=output;

							setTimeout(function() {
								$scope.hd_list[id].juli = output;
								$scope.$broadcast('scroll.refreshComplete');
							});
							//$scope.hd_list[i].juli=output; 	
						}
					});

					transit.search(pt, str);

				} else {
					alert('failed' + this.getStatus());
				}
			}, {
				enableHighAccuracy: true
			})

		}
		//最新活动
		$scope.hd_new = function() {
			var json = JSON.stringify({
				内容: $scope.title
			})
			$scope.hd_list = [];

			$http.post(ServerAddress + "api/hd_GetNewActivities/get", json).success(function(data) {

					data = JSON.parse(data);
					$scope.sf_new = true;
					$scope.moredata = false;
					console.log(data.length);
					for(var i = 0; i < data.length; i++) {

						var kssj = new Date(data[i].开始时间).getTime() - (60000 * 60 * 8);;
						$scope.hd_list.push({
							Id: data[i].id,
							title: data[i].标题,
							ksdate: kssj,
							hdfm: data[i].主题,
							juli: ''
						});
						$scope.zhdizi(data[i].地址, $scope.hd_list.length - 1);
						$scope.juli(data[i].地址, $scope.hd_list.length - 1);
						$scope.count = data[i].id;
						console.log($scope.count);

					}
					$scope.cx = true;
					if(data.length < 4) {
						console.log(1);
						$scope.moredata = true;
					}
				})
				.finally(function() {
					// Stop the ion-refresher from spinning
					$scope.$broadcast('scroll.refreshComplete');
				});
		}
		//最热活动
		$scope.hd_re = function() {
			$scope.hd_list = [];
			var json = JSON.stringify({
				内容: $scope.title
			})
			$scope.sf_new = false;
			$scope.count = 0;
			$scope.moredata = false;
			$http.post(ServerAddress + "api/hd_GetheatActivities/get", json).success(function(data) {
					$scope.hd_list = [];
					data = JSON.parse(data);

					for(var i = 0; i < data.length; i++) {

						var kssj = new Date(data[i].开始时间).getTime() - (60000 * 60 * 8);;
						$scope.hd_list.push({
							Id: data[i].id,
							title: data[i].标题,
							ksdate: kssj,
							hdfm: data[i].主题,
							juli: ''
						});
						$scope.zhdizi(data[i].地址, $scope.hd_list.length - 1);
						$scope.juli(data[i].地址, $scope.hd_list.length - 1);
						setTimeout(function() {
							$scope.hd_list
						}, 3000);
						//$scope.hd_list[i].juli=i;

					}
					if(data.length < 4) {

						$scope.moredata = true;
					}
				})
				.finally(function() {
					// Stop the ion-refresher from spinning
					$scope.$broadcast('scroll.refreshComplete');
				});
		}
		$scope.hd_new(); //默认显示最新
		//下拉刷新
		$scope.doRefresh = function() {
			if($scope.sf_new)
				$scope.hd_new();
			else
				$scope.hd_re();
			console.log($scope.moredata);
		}
		$scope.sx_new = function() {
			var json = JSON.stringify({
				内容: $scope.title,
				Id: $scope.count
			})

			$http.post(ServerAddress + "api/hd_GetNewActivities/get2", json).success(function(data) {

					data = JSON.parse(data);
					$scope.sf_new = true;
					$scope.moredata = false;

					for(var i = 0; i < data.length; i++) {

						var kssj = new Date(data[i].开始时间).getTime() - (60000 * 60 * 8);;
						$scope.hd_list.push({
							Id: data[i].id,
							title: data[i].标题,
							ksdate: kssj,
							hdfm: data[i].主题,
							juli: ''
						});
						$scope.zhdizi(data[i].地址, $scope.hd_list.length - 1);
						$scope.juli(data[i].地址, $scope.hd_list.length - 1);
						$scope.count = data[i].id;

					}
					if(data.length < 4) {

						$scope.moredata = true;
					}

				})
				.finally(function() {
					// Stop the ion-refresher from spinning
					$scope.$broadcast('scroll.infiniteScrollComplete');
				});
		}
		$scope.cs = function() {
			$timeout(function() {
				$scope.moredata = false;

			}, 2000);

		}
		$scope.cs();
		$scope.sx_re = function() {
			$scope.count = $scope.count + 1
			var json = JSON.stringify({
				内容: $scope.title,
				Id: $scope.count
			})

			$http.post(ServerAddress + "api/hd_GetheatActivities/get2", json).success(function(data) {

					data = JSON.parse(data);
					$scope.sf_new = false;
					$scope.moredata = false;

					for(var i = 0; i < data.length; i++) {

						var kssj = new Date(data[i].开始时间).getTime() - (60000 * 60 * 8);;
						$scope.hd_list.push({
							Id: data[i].id,
							title: data[i].标题,
							ksdate: kssj,
							hdfm: data[i].主题,
							juli: ''
						});
						$scope.zhdizi(data[i].地址, $scope.hd_list.length - 1);
						$scope.juli(data[i].地址, $scope.hd_list.length - 1);
						$scope.count = data[i].id;

					}
					if(data.length < 4) {
						$scope.moredata = true;
					}
				})
				.finally(function() {
					// Stop the ion-refresher from spinning
					$scope.$broadcast('scroll.infiniteScrollComplete');
				});
		}
		//上拉加载
		$scope.loadMore = function() {
			if($scope.sf_new)
				$scope.sx_new();
			else
				$scope.sx_re();

		};

	})
	.controller('publishCtrl', function($scope) {
		$scope.$on('$ionicView.beforeEnter', function() {
			mapcont = '';
		});

	})

	//设置
	.controller('setCtrl', function($scope) {
		$scope.esc = function() {
			localStorage.removeItem('userphone');
			location.href = '#/tab/Selected';
		}
	})
	//我的收藏
	.controller('love-activityCtrl', function($scope, $http) {
		$scope.zhdizi = function(dizhi, i) {
			var myGeo = new BMap.Geocoder();
			// 将地址解析结果显示在地图上,并调整地图视野
			myGeo.getPoint(dizhi, function(point) {
				if(point) {

					myGeo.getLocation(point, function(rs) {
						var addComp = rs.addressComponents;
						console.log(addComp.district);
						$scope.hd_list[i].dizi = addComp.district;
					});
				} else {

					$scope.hd_list[i].dizi = dizhi;
				}
			}, "北京市");
		}

		$scope.hd_list = []; //活动列表

		//最新活动
		$scope.hd_new = function() {

			$scope.hd_list = [];

			$http.get(ServerAddress + "api/like/" + localStorage.getItem('userphone')).success(function(data) {

					data = JSON.parse(data);

					console.log(data.length);
					for(var i = 0; i < data.length; i++) {

						var kssj = new Date(data[i].开始时间).getTime() - (60000 * 60 * 8);;
						$scope.hd_list.push({
							Id: data[i].id,
							title: data[i].标题,
							ksdate: kssj,
							zt: data[i].状态,
							hdfm: data[i].主题
						});
						$scope.zhdizi(data[i].地址, $scope.hd_list.length - 1);

						console.log($scope.count);

					}

				})
				.finally(function() {
					// Stop the ion-refresher from spinning
					$scope.$broadcast('scroll.refreshComplete');
				});
		}
		$scope.hd_new(); //默认显示最新
		//下拉刷新
		$scope.doRefresh = function() {

			$scope.hd_new();

		}

	})
	//报名凭证
	.controller('me-bmpzCtrl', function($scope, $http,$ionicPopup) {
	console.log(11111);
	
	$scope.showAlert = function(url) {
             var alertPopup = $ionicPopup.alert({
				   cssClass:'er-popup',
             		 title:'报名凭证',
               template:'<img  src="http://pan.baidu.com/share/qrcode?w=150&h=150&url='+url+'"> '
             });
             alertPopup.then(function(res) {
               console.log('Thank you for not eating my delicious ice cream cone');
             });
           };
      
		$scope.zhdizi = function(dizhi, i) {

			var myGeo = new BMap.Geocoder();
			// 将地址解析结果显示在地图上,并调整地图视野
			myGeo.getPoint(dizhi, function(point) {
				if(point) {

					myGeo.getLocation(point, function(rs) {
						var addComp = rs.addressComponents;
						console.log(addComp.district);
						$scope.hd_list[i].dizi = addComp.district;
					});
				} else {

					$scope.hd_list[i].dizi = dizhi;
				}
			}, "北京市");
		}

		$scope.hd_list = []; //活动列表

		
		$scope.hd_new = function() {

			$scope.hd_list = [];

			$http.get(ServerAddress + "api/me_signup/" + localStorage.getItem('userphone')).success(function(data) {

					data = JSON.parse(data);

					console.log(data.length);
					for(var i = 0; i < data.length; i++) {

						var kssj = new Date(data[i].开始时间).getTime() - (60000 * 60 * 8);;
						$scope.hd_list.push({
							Id: data[i].id,
							title: data[i].标题,
							ksdate: kssj,
							zt: data[i].状态,
							hdfm: data[i].主题,
							ewm:data[i].二维码
						});
						$scope.zhdizi(data[i].地址, $scope.hd_list.length - 1);

						console.log($scope.count);

					}

				})
				.finally(function() {
					// Stop the ion-refresher from spinning
					$scope.$broadcast('scroll.refreshComplete');
				});
		}
		$scope.hd_new(); //默认显示最新
		//下拉刷新
		$scope.doRefresh = function() {

			$scope.hd_new();

		}

	})

	//我的活动
	.controller('me-activityCtrl', function($scope, $http) {
		$scope.zhdizi = function(dizhi, i) {

			var myGeo = new BMap.Geocoder();
			// 将地址解析结果显示在地图上,并调整地图视野
			myGeo.getPoint(dizhi, function(point) {
				if(point) {

					myGeo.getLocation(point, function(rs) {
						var addComp = rs.addressComponents;
						console.log(addComp.district);
						$scope.hd_list[i].dizi = addComp.district;
					});
				} else {

					$scope.hd_list[i].dizi = dizhi;
				}
			}, "北京市");
		}

		$scope.hd_list = []; //活动列表

		//最新活动
		$scope.hd_new = function() {

			$scope.hd_list = [];

			$http.get(ServerAddress + "api/hd_GetmeActivities/" + localStorage.getItem('userphone')).success(function(data) {

					data = JSON.parse(data);

					console.log(data.length);
					for(var i = 0; i < data.length; i++) {

						var kssj = new Date(data[i].开始时间).getTime() - (60000 * 60 * 8);;
						$scope.hd_list.push({
							Id: data[i].id,
							title: data[i].标题,
							ksdate: kssj,
							zt: data[i].状态,
							hdfm: data[i].主题
						});
						$scope.zhdizi(data[i].地址, $scope.hd_list.length - 1);

						console.log($scope.count);

					}

				})
				.finally(function() {
					// Stop the ion-refresher from spinning
					$scope.$broadcast('scroll.refreshComplete');
				});
		}
		$scope.hd_new(); //默认显示最新
		//下拉刷新
		$scope.doRefresh = function() {

			$scope.hd_new();

		}

	})

	.controller('AccountCtrl', function($scope) {
		$scope.settings = {
			enableFriends: true
		};
	});

var zcphone; //注册手机号
var zcmima;
var wait = 60;
//注册页面
function time() {

	if(wait == 0) {
		document.getElementById('cx').removeAttribute("disabled");
		document.getElementById('cx1').innerHTML = "重新发送";
		wait = 60;
	} else {
		document.getElementById('cx').setAttribute("disabled", true);
		document.getElementById('cx1').innerHTML = +wait + "秒后重新发送";
		wait--;

		setTimeout(function() {
				time()
			},
			1000)
	}
}

//忘记密码页面
function ftime() {

	if(wait == 0) {
		document.getElementById('forget1').removeAttribute("disabled");
		document.getElementById('forget2').innerHTML = "重新发送";
		wait = 60;
	} else {
		document.getElementById('forget1').setAttribute("disabled", true);
		document.getElementById('forget2').innerHTML = +wait + "秒后重新发送";
		wait--;

		setTimeout(function() {
				ftime()
			},
			1000)
	}
}
//随机数 min~max之间
function GetRandomNum(Min, Max) {
	var Range = Max - Min;
	var Rand = Math.random();
	return(Min + Math.round(Rand * Range));
}
var mapcont = ''; //地图内容

